﻿
Public Class AccesoDatos
    Dim cmd As New Data.SqlClient.SqlCommand
    Dim conexion As New Data.SqlClient.SqlConnection
    Dim ubicacionProyecto As String = System.IO.Directory.GetCurrentDirectory()
    Dim ubicacionActual As String = ubicacionProyecto.Substring(0, ubicacionProyecto.Length - 9)
    Dim stringConexion As String = "Data Source=.\SQLEXPRESS;AttachDbFilename=" & ubicacionActual & "TPI_PAV.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"

    Public Sub conectar()
        Me.conexion.ConnectionString = stringConexion
        Me.conexion.Open()
        Me.cmd.Connection = conexion
        Me.cmd.CommandType = CommandType.Text
    End Sub

    Public Function consultaReader(ByVal consulta As String) As Data.DataTable
        Dim tabla As New Data.DataTable
        Me.conectar()
        Me.cmd.CommandText = consulta
        tabla.Load(cmd.ExecuteReader)
        Me.conexion.Close()
        Return tabla
    End Function

    Public Sub consultaNonQuery(ByVal consulta As String)
        Me.conectar()
        Me.cmd.CommandText = consulta
        cmd.ExecuteNonQuery()
        Me.conexion.Close()
    End Sub

End Class
